package com.yanchengtect.demo.progress.rollback.activity.dao;

import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.yanchengtect.demo.progress.dao.BaseDao;
import com.yanchengtect.demo.progress.dao.RowMapperUtil;
import com.yanchengtect.demo.progress.rollback.activity.domain.User;

/**
* @author 文心雕龙 Email：xuwenlong@shike8888.com
* @version 创建时间：2018年9月6日 下午7:20:38
* 类说明
*/
@Repository
public class UserDao extends BaseDao<User> {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public User findById(int id) {
		String sql = "select user_id,low_weight,base_weight,high_weight from `user` where user_id = ? ";
		log.debug(sql);
		List<User> list = jdbcTemplate.query(sql, new Object[] {id},new RowMapperUtil(User.class));
		  
		  if (list.size()>0) {
			return list.get(0);
		 }else {
			 return null;
		 }
	}

	public int updateOne(User user) {
		HashMap<String,Object> conditions = new HashMap<String, Object>();
		conditions.put("user_id", user.getUser_id());
		user.setUser_id(null);
		return update("user", user, conditions);
	}
}
